package com.sunwoda.springbootredis.result;

import com.sunwoda.springbootredis.entity.ResultEntity;
import com.sunwoda.springbootredis.enumcode.ResultCode;

/**
 * @program: springbootredis
 * @description: 返回类
 * @author: SGR
 * @create: 2021-09-18 15:23
 **/
public class Result {

    public static ResultEntity success(){
        ResultEntity<Object> entity = new ResultEntity<>();
        entity.setCode(ResultCode.SUCCESS.getCode());
        entity.setMsg(ResultCode.SUCCESS.getMsg());
        return entity;
    }

    public static ResultEntity fail(){
        ResultEntity<Object> entity = new ResultEntity<>();
        entity.setCode(ResultCode.FAILT.getCode());
        entity.setMsg(ResultCode.FAILT.getMsg());
        return entity;
    }

    public static <T> ResultEntity customSuccess(T data){
        ResultEntity<Object> entity = new ResultEntity<>();
        entity.setCode(ResultCode.SUCCESS.getCode());
        entity.setMsg(ResultCode.SUCCESS.getMsg());
        entity.setData(data);
        return entity;
    }

    public static <T> ResultEntity customFail(T data){
        ResultEntity<Object> entity = new ResultEntity<>();
        entity.setCode(ResultCode.FAILT.getCode());
        entity.setMsg(ResultCode.FAILT.getMsg());
        entity.setData(data);
        return entity;
    }

    public static <T> ResultEntity custom(int code,String msg,T data){
        ResultEntity<Object> entity = new ResultEntity<>();
        entity.setCode(code);
        entity.setMsg(msg);
        entity.setData(data);
        return entity;
    }

}
